package com.example.myapplication.fragment

import com.example.myapplication.my_view_model.NavViewModel
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.example.myapplication.R
import com.example.myapplication.databinding.FragmentDetailBinding

class DetailFragment : Fragment() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {

        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        var viewModel: NavViewModel? = activity?.let {
            ViewModelProvider(it)[NavViewModel::class.java]
        }
        var dataBinding = DataBindingUtil.inflate<FragmentDetailBinding>(inflater,R.layout.fragment_detail,container,false)
        dataBinding.data = viewModel
        dataBinding.lifecycleOwner = activity
        dataBinding.button23.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_detailFragment3_to_homeFragment5))
//        dataBinding.button23.setOnClickListener(object : View.OnClickListener {
//            override fun onClick(v: View?) {
//                val controller: NavController = Navigation.findNavController(v!!)
//                controller.popBackStack()
//            }
//        })
        return dataBinding.root
    }

    companion object {

        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            DetailFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}